home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 19.zip / BS1 part 19 / how to learn assembler.adf / CH4 / 4_3_3Bhex-conv.asm < prev    next >
Assembly Source File  |  1988-02-25  |  928b  |  32 lines

  1. ;(4.3.3B) hex convert
  2. hexin:                   ; Converting a hex number
  3.     clr.l     d1         ; First erase D1
  4.     move.l    #string,a0 ; Address of the string in A0
  5. hexinloop:
  6.     tst.b     (a0)       ; Test digit
  7.     beq       hexinok    ; If zero, then done
  8.     bsr       nibblein   ; Convert digit
  9.     lsl.l     #4,d1      ; Shift result
  10.     or.b      d0,d1      ; Insert nibble
  11.     bra       hexinloop  ; And continue
  12.  
  13. hexinok:
  14.     rts
  15.  
  16. nibblein:                ; Convert the nibble from (A0)
  17.     clr.l     d0         ; Erase D0
  18.     move.b    (a0)+,d0   ; Get digit, increment A0
  19.     sub       #'A',d0    ; Subtract $41
  20.     bcc       ischar     ; No problem, in the range A-F
  21.     add       #7,d0      ; Else correct value
  22.  
  23. ischar:
  24.     add       #10,d0     ; Correct value
  25.     rts
  26.  
  27.  
  28. string:  DC.B  '56789ABC',00   ; 8 Digit string ending with a null byte
  29.                                ; that we want to convert
  30.  
  31.    end
  32.